<template>
	<view class="page">
		<view class="bg">
			<image class="img_1" src="../../static/image/bg_01.png" mode=""></image>
			<image class="img_2" src="../../static/image/home_center.png" mode=""></image>
		</view>
		<view class="List">
			<view class="box" @click="go_xinlu">
				<span class="sp_1">心率</span>
				<image class="img"  src="../../static/image/xinlu.png" mode=""></image>
				<span class="sp_2">{{xinlu}}</span>
			</view>
			<view class="box">
				<span class="sp_1">信号</span>
				<image class="img"  src="../../static/image/shouhuan.png" mode="">
				</image>
				<span class="sp_2">{{xinhao}} <span style="font-size: 45rpx;">%</span></span>
			</view>
			<view class="box" @click="go_bushu">
				<span class="sp_1">步数</span>
				<image class="img"  src="../../static/image/bushu.png" mode=""></image>
				<span class="sp_2">{{bushu}}</span>
				<span class="sp_3" >步</span>
			</view>
			<view class="box">
				<span class="sp_1">电量</span>
				<image class="img"  src="../../static/image/dianliang.png" mode=""></image>
				<span class="sp_2">{{dianliang}} <span style="font-size: 45rpx;">%</span></span>
			</view>
		</view>
		<uni-popup ref="agreement" type="center" style="border-radius: 26rpx;">
			<view class="agreement-height">
				<image class="img_1" src="../../static/image/bg_01.png" mode=""></image>
				<view class="box" style="border: none;">
					<!-- <label class="left">病患手表imei号</label> -->
					<input class="right_inp" v-model="binghuan_phone" type="number" placeholder="绑定病患手表设备编号" />
					<button @click="add_binghuan" class="bt">绑定</button>
				</view>
			</view>
		</uni-popup>

	</view>
</template>

<script>
	import {
		FindHeartRateAndLocation,
		BindPatientRequest
	} from '@/utils/api.js'
	export default {
		components: {},
		data() {
			return {
				xinlu: '',
				dianliang: '',
				bushu: '',
				xinhao: '',
				binghuan_phone: '',
			}
		},
		methods: {
			//获取数据
			Get_message() {
				FindHeartRateAndLocation({
					token: this.$store.state.vx_token,
					body: ""
				}).then(res => {
					console.log('测试', res);
					if (res.code == 200) {
						this.dianliang = res.data.device.electricQuantity
						this.bushu = res.data.steps.step1
						this.xinhao = res.data.device.signal
						this.xinlu = res.data.heartRate.heartRate1
					} else if (res.code == 802) {
						uni.showToast({
							title: `${res.message}`,
							icon: 'none',
							duration: 3000
						})
						this.$refs.agreement.open('center')
					}
				}).catch(err => {
					console.log(err);
				})
			},
			add_binghuan() {
				BindPatientRequest({
					body: {
						imei: this.binghuan_phone,
					},
					token: this.$store.state.vx_token
				}).then(res => {
					console.log('家属绑定患者:', res);
					if (res.code == 200) {
						uni.showToast({
							title: `绑定成功`,
							icon: 'success',
							duration: 2000
						})
						this.$refs.agreement.close()
						this.Get_message()
					}
				}).catch(err => {
					console.log(err);
				})
			},
			//往期心率
			go_xinlu() {
				uni.navigateTo({
					url: '/page_xinlu/old_xinlu/index'
				})
			},
			//近期步数
			go_bushu() {
				uni.navigateTo({
					url: '/page_xinlu/bushu_info/index'
				})
			}
		},
		onLoad() {
			// this.Get_message()
		},
		onShow() {
			this.Get_message()
		}
	}
</script>

<style scoped lang="scss">
	.page {
		width: 100vw;
		height: 100vh;
		position: relative;
		display: flex;
		flex-direction: column;
		overflow: hidden;

		.bg {
			margin: 0 auto;
			position: relative;
			width: 790rpx;
			height: 650rpx;

			.img_1 {
				width: 100%;
				height: 100%;
			}

			.img_2 {
				width: 410rpx;
				height: 410rpx;
				position: absolute;
				top: 150rpx;
				left: 172rpx;
			}
		}

		.List {
			display: flex;
			flex-wrap: wrap;
			margin-left: 30rpx;
			margin-top: 50rpx;

			.box {
				position: relative;
				margin: 15rpx;
				width: 329rpx;
				height: 203rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 28rpx 0rpx #E8EEEF;
				border-radius: 30rpx;

				.sp_1 {
					position: absolute;
					display: inline-block;
					bottom: 32rpx;
					left: 48rpx;
					width: 56rpx;
					height: 28rpx;
					font-weight: 400;
					font-size: 28rpx;
					color: #333738;
				}

				.img {
					position: absolute;
					width: 88rpx;
					height: 88rpx;
					top: 30rpx;
					left: 29rpx;
				}

				.sp_2 {
					position: absolute;
					display: inline-block;
					top: 40%;
					right: 20rpx;	
					width: 200rpx;
					height: 41rpx;
					text-align: center;
					font-weight: 400;
					font-size: 52rpx;
					color: #333738;
				}

				.sp_3 {
					position: absolute;
					display: inline-block;
					bottom: 38rpx;
					right: 38rpx;
					font-size: 22rpx;
					color: #63696B;
				}
			}
		}

		.agreement-height {
			width: 615rpx;
			height: 30vh;
			margin: 0 auto;
			border-radius: 26rpx;
			background-color: #ffffff;
			position: relative;
			text-align: center;
			overflow: hidden;
			.box{
				position: absolute;
				width: 100%;
				height: 30vh;
				top: 0;

				.right_inp{
					position: absolute;
					font-size: 30rpx;
					background-color: #FFFFFF;
					width: 70%;
					height: 15%;
					border-radius: 20rpx;
					top: 150rpx;
					left: 15%;
				}
				.bt{
					position: absolute;
					width: 50%;
					top: 280rpx;
					left: 16%;
					width: 400rpx;
					height: 70rpx;
					background: #2CB0C5;
					border-radius: 50rpx;
					font-weight: 500;
					font-size: 30rpx;
					color: #FFFFFF;
					line-height: 70rpx
				}
			}
		}
	}
</style>